/**
 * 
 */
package cn.agiledata.bank.facade.helper;

import java.util.Random;

/**
 * 编码助手
 * 
 * @author 马贤波
 *
 * 2006-7-18
 */
public class CodationHelper {
	
	private static Random RAND = new Random () ;
	
	public String generateMobileSMSVericode() {
		String vericode = this.generateRandomCode(8, "[0-9]") ;
		return vericode ;
	}
	
	public String generateMobileSMSVericode1()
	{
		String vericode = this.generateRandomCode(6, "[0-9]") ;
		return vericode ;
	}
	
	
	private String generateRandomCode (int digit, String regex) {
		StringBuffer content = new StringBuffer () ;
		
		int i = 0 ;
		while ( i < digit ) {
			byte[] tmp = new byte[1] ;
			
			RAND.nextBytes(tmp) ;
			String chr = new String(tmp) ;
			
			if (chr.matches(regex)) {
				content.append(chr) ;
				i ++ ;
			}
			
		}
		
		String result = content.toString() ;
		return result ;
	}

}
